package com.duoec.doc.doclet.annotation.param;

import com.alibaba.fastjson.JSON;
import com.duoec.doc.doclet.helper.AnnotationHelper;
import com.duoec.doc.doclet.pojo.EntityRef;
import com.sun.javadoc.AnnotationDesc;

import java.io.Serializable;
import java.util.Map;

/**
 * @author xuwenzhen
 * @date 2019/3/4
 */
public class RequestHeaderAnnotation extends BaseSpringMvcParamAnnotation {
    /**
     * 获取注解
     *
     * @return 注解类全名
     * @demo org.springframework.web.bind.annotation.RequestParam
     */
    @Override
    public String getAnnotationFullClass() {
        return "org.springframework.web.bind.annotation.RequestHeader";
    }

    /**
     * 在文档上显示的注解
     *
     * @return 在文档上显示的注解名称
     * @demo @RequestParam
     */
    @Override
    public String getDocAnnotation() {
        return "@RequestHeader";
    }

    /**
     * 分析参数注解
     *
     * @param param          当前参数
     * @param annotationDesc 注解
     */
    @Override
    public boolean analyse(EntityRef param, AnnotationDesc annotationDesc) {
        Map<String, Serializable> annotationParams = AnnotationHelper.getAnnotations(annotationDesc);
        if (!annotationParams.isEmpty()) {
            param.setAnnotationParams(annotationParams);
            Boolean required = (Boolean) annotationParams.get("required");
            if (required != null) {
                param.setRequired(required);
            } else {
                param.setRequired(true);
            }
        } else {
            param.setRequired(true);
        }

        param.setAnnotation(getDocAnnotation());
        return true;
    }
}
